<template>
  <page-header-wrapper :title="false">
    <a-card title="超时顾问管理">
      <a-spin :spinning="loading">
        <div class="table-page-search-wrapper">
          <a-form-model :model="queryParam" layout="inline">
            <a-row :gutter="10">
              <a-col :md="6" :sm="24">
                <a-form-model-item label="选择顾问">
                  <a-input v-model="queryParam['filter[username]']" placeholder="输入要查看的顾问" />
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="24">
                      <span class="table-page-search-submitButtons">
                        <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                        <a-button style="margin-left: 8px" type="default" @click="reset">重置</a-button>
                      </span>
              </a-col>
            </a-row>
          </a-form-model>
        </div>
        <s-table
          bordered
          ref="table"
          :row-key="(record) => record.uid"
          :columns="timeoutColumns"
          :data="timeoutData"
        >
          <template slot="timeout_num" slot-scope="text,record">
            <a @click="onModal(record.uid)">{{ text }}</a>
          </template>
          `
          <template slot="action" slot-scope="text,record">
            <a-button size="small" style="margin-right:5px" type="primary" @click="unLock(record.uid)">解除锁定</a-button>
            <a-button size="small" style="margin-right:5px" type="danger">转移</a-button>
            <a-button size="small" type="default" @click="onRefresh(record.uid)">刷新</a-button>
          </template>
        </s-table>
      </a-spin>
    </a-card>
    <a-modal
      title="超时未联系列表"
      v-model="visible"
      :width="800"
      :destroy-on-close="true"
      :footer="null"
    >
      <s-table
        ref="table2"
        size="small"
        :row-key="(record) => record.customer_id"
        :columns="listColumns"
        :data="listData"
      >
        <template slot="customer_name" slot-scope="text,record">
          <a @click="toCustomerDetail(record.customer_id)">{{ text }}</a>
        </template>
      </s-table>
    </a-modal>
  </page-header-wrapper>
</template>

<script>
import { STable } from '@/components'
import col from '@/columns/member'
import { getTimeoutCustomer, getTimeoutMember, refresh, unlockCustomer } from '@/api/member'

export default {
  components: {
    STable
  },
  name: 'TimeoutCustomer',
  data () {
    return {
      timeoutColumns: col.timeout,
      timeoutData: parameters => {
        return getTimeoutMember(Object.assign(parameters, this.queryParam)).then(res => {
          return res.result
        })
      },
      listColumns: col.outlist,
      listData: parameters => {
        return getTimeoutCustomer(Object.assign(parameters, this.queryParam2)).then(res => {
          return res.result
        })
      },
      visible: false,
      uid: '',
      queryParam: {},
      queryParam2: {},
      loading: false
    }
  },
  methods: {
    toCustomerDetail (id) {
      this.$router.push({ name: 'CustomerDetail', params: { id } })
      this.visible = false
    },
    onModal (id) {
      this.visible = true
      this.queryParam2['filter[uid]'] = id
    },
    onRefresh (id) {
      this.loading = true
      refresh(id).finally(() => {
        this.loading = false
        this.$refs.table.refresh()
      })
    },
    unLock (id) {
      const app = this
      app.$confirm({
        title: '确定解除领取限制吗',
        onOk: () => {
          unlockCustomer(id).then(res => {
            if (res.status === 0) {
              app.$refs.table.refresh(true)
            } else {
              app.$warning({
                title: res.msg
              })
            }
          })
        }
      })
    },
    reset () {
      this.queryParam = {}
      this.$refs.table.refresh(true)
    }
  }
}
</script>

<style scoped>

</style>
